package com.five.service.impl;


import com.five.mapper.BaseMapper;
import com.five.query.QueryPage;
import com.five.result.PageResult;
import com.five.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;


    @Override
    public T queryById(Long id) {
        return this.baseMapper.queryById(id);
    }

    @Override
    public PageResult<T> queryByPage(QueryPage<T> t) {
        List<T> dataList = baseMapper.queryPage(t);
        Long count = baseMapper.queryCount(t.getT());
        PageResult<T> departmentPageResult = new PageResult<>();
        departmentPageResult.setPageNum(t.getPageNum());
        departmentPageResult.setPageSize(t.getPageSize());
        departmentPageResult.setDataList(dataList);
        departmentPageResult.setTotalCount(count);
        departmentPageResult.setTotalPage();
        return departmentPageResult;
    }

    @Override
    public boolean insert(T t) {
        return this.baseMapper.insert(t) > 0;
    }

    @Override
    public boolean update(T t) {
        return this.baseMapper.update(t) > 0;
    }

    @Override
    public boolean deleteById(Long id) {
        return this.baseMapper.deleteById(id) > 0;
    }

    @Override
    public boolean deleteByIds(List<Long> ids) {
        return this.baseMapper.deleteBatch(ids) > 0;
    }

    @Override
    public List<T> queryAll() {
        return this.baseMapper.queryAll();
    }
}
